/**
 * @file TEST_task_with_args.c
 * @author Linquan 
 * @brief  新增task支持外部传入参数，支持传入单个int、float、字符串、自定义结构体
 * 并提供宏封装，用于正确创建和获取传入参数
 * @version 0.1
 * @date 2025-10-10
 * 
 * @copyright Copyright (c) 2025
 * 
 * 
 * 
 */

#include "app_config.h"
#if TEST_TASK_WITH_ARGS

#include "tasks.h"


int task_args_int(task_param_t* args)
{
    int val = GET_PARAM_INT(args);

	printf("int args: %#X\r\n", val);
	return MS_(1000) ; 
}


int task_args_float(task_param_t* args)
{
    float val = GET_PARAM_FLOAT(args);

	printf("float args: %f\r\n", val);
	return MS_(1000) ; 
}


int task_args_string(task_param_t* args)
{
    char* val = GET_PARAM_PTR(args);

	printf("string args: %s\r\n", val);
	return MS_(1000) ; 
}



typedef struct 
{
   int a;
   int b;
}obj_t;

// 传入变量需要是全局的，不能所局部变量
obj_t obj =
{
    .a = 11,
    .b = 22,
};

int task_args_obj(task_param_t* args)
{
    // 注意这里是建立一个指针来取得传入参数
    obj_t* val =  GET_PARAM_OBJ(args, obj_t);

	printf("obj args: a = %d, b = %d \r\n", val->a, val->b);

    obj.a++;
    obj.b++;

	return MS_(1000) ; 
}


void Add_all_task(void* ptr)
{
    Master_task_add_with_para(&task_args_int, 0, TASK_PARAM_INT(0XAABBCCDD));
    Master_task_add_with_para(&task_args_float, 0, TASK_PARAM_FLOAT(3.1415926));
    Master_task_add_with_para(&task_args_string, 0, TASK_PARAM_PTR("string-12345"));      
    Master_task_add_with_para(&task_args_obj, 0, TASK_PARAM_OBJ(&obj));

}
EXPORT_Lv6_APP_SINGLE(Add_all_task,NULL);









#endif

















